<?php

namespace app\index\controller\my;

use app\index\service\HelpService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use ShidianUtil\Utils\CheckUtil;
use think\APP;
use think\Request as Request;

/**
 * Help 控制器
 * Class Help
 * @package app\my\controller
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 */
class Help
{
    // 请求参数
    private Request $request;

    // service
    private HelpService $service;

    public function __construct(Request $request, HelpService $helpService)
    {
        $this->request = $request;
        $this->service = $helpService;
    }

    /**
     * 列表
     * @return ApiResponse
     * @url /my/help/index
     */
    public function index(): ApiResponse
    {
        $request = $this->request;

        $categoryId = $request->param('categoryId', null);
        $page = $request->param('page', 1);
        $page_size = $request->param('page_size', 20);

        return ApiResponse::success($this->service->index(null, $categoryId, $page, $page_size));
    }

    /**
     * 详情
     * @return ApiResponse
     * @url /my/help/read
     */
    public function read(): ApiResponse
    {
        $request = $this->request;

        $id = $request->param('id');

        if (!CheckUtil::isId($id)) {
            return ApiResponse::fail('缺少id参数');
        }

        return ApiResponse::success($this->service->read(null, $id));
    }

}
